package at.fhooe.mc.msports;

import at.fhooe.mc.msports.ui.ColorableLabel;
import at.fhooe.mc.msports.ui.CustomizedButton;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class ZoneSelectionScreen extends FullScreen{

	private ObjectChoiceField zone;
	
	public ZoneSelectionScreen(){
		super(VERTICAL_SCROLL);
		setBackground(BackgroundFactory.createSolidBackground(
				Color.BLACK));
		
		//Header
		ColorableLabel lblHeader = new ColorableLabel("Select your preferred zone", Color.LIGHTBLUE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,20));
		lblHeader.setMargin(20, 0, 0, 0);
		add(lblHeader);
		
		ColorableLabel lblHeader0 = new ColorableLabel("Do not participate regularly in programmed recreation sport or heavy physical activity", Color.GRAY,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lblHeader0.setMargin(20, 0, 0, 0);
		add(lblHeader0);
		
		ColorableLabel lbl0 = new ColorableLabel("Zone 0: Avoid walking or exertion", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl0.setMargin(10, 0, 0, 0);
		add(lbl0);
		
		ColorableLabel lbl1 = new ColorableLabel("Zone 1: Walk for pleasure", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl1.setMargin(10, 0, 0, 0);
		add(lbl1);
		
		ColorableLabel lblHeader1 = new ColorableLabel("Participate regularly in recreation or work requiring modest physical activity (golf, tennis, ...)", Color.GRAY,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lblHeader1.setMargin(20, 0, 0, 0);
		add(lblHeader1);
		
		ColorableLabel lbl2 = new ColorableLabel("Zone 2: 10 to 60 minutes per week", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl2.setMargin(10, 0, 0, 0);
		add(lbl2);
		
		ColorableLabel lbl3 = new ColorableLabel("Zone 3: Over 60 minutes per week", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl3.setMargin(10, 0, 0, 0);
		add(lbl3);
		
		ColorableLabel lblHeader2 = new ColorableLabel("Participate regularly in heavy physical exercise such as running, jogging, cycling or swimming", Color.GRAY,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lblHeader2.setMargin(20, 0, 0, 0);
		add(lblHeader2);
		
		ColorableLabel lbl4 = new ColorableLabel("Zone 4: Run less than 1 mile per week (< 30 min)", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl4.setMargin(10, 0, 0, 0);
		add(lbl4);
		
		ColorableLabel lbl5 = new ColorableLabel("Zone 5: Run 1 to 5 miles per week (< 60 min.)", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl5.setMargin(10, 0, 0, 0);
		add(lbl5);
		
		ColorableLabel lbl6 = new ColorableLabel("Zone 6: Run 5 to 10 miles per week (< 3 hrs.)", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl6.setMargin(10, 0, 0, 0);
		add(lbl6);
		
		ColorableLabel lbl7 = new ColorableLabel("Zone 7: Run over 10 miles per week (> 3 hrs.)", Color.WHITE,
				USE_ALL_WIDTH|DrawStyle.HCENTER, Font.getDefault().derive(Font.PLAIN,16));
		lbl7.setMargin(10, 0, 0, 0);
		add(lbl7);
		
		//Zone
		HorizontalFieldManager hfmZone = new HorizontalFieldManager();
		
		zone = new ObjectChoiceField("",new String[]{"0 - No sports",
				"1 - Walk for pleasure",
				"2 - Up to 1h per week",
				"3 - Over 1h per week",
				"4 - Less than 1 mile per week",
				"5 - 1 to 5 miles per week",
				"6 - 5 to 10 miles per week",
				"7 - Over 10 miles per week"},
				0,USE_ALL_WIDTH|Field.FIELD_HCENTER){
			protected void paint(Graphics graphics) {
				graphics.setColor(Color.WHITE);
				super.paint(graphics);
			};

			public Object getChoice(int index) throws IllegalArgumentException {
				return new Integer(index);
			}
		};
		zone.setPadding(6,0,0,0);
		zone.setFont(Font.getDefault().derive(Font.PLAIN,15));
		hfmZone.add(zone);
		hfmZone.setMargin(10,0,0,24);
		add(hfmZone);
		
		//Commit button
		CustomizedButton btnCommit = new CustomizedButton(USE_ALL_WIDTH|Field.FIELD_HCENTER){
    		protected void layout(int width, int height) {
    			super.layout(getPreferredWidth(), getPreferredHeight());
    			setExtent(getPreferredWidth(), getPreferredHeight());
    		};
    		
    		protected boolean navigationUnclick(int status, int time) {
    			onStateChanged();
    			return true;
    		};
    		
    		protected boolean trackwheelUnclick(int status, int time) {
    			onStateChanged();
    			return true;
    		};
    		
    		public void onStateChanged(){
    				PersonalData.setZone(zone.getSelectedIndex());
    				PersonalData.updateData();
    				popScreen();
    		}
		};
		
		btnCommit.setWidth(100);
		btnCommit.setHeight(30);
		btnCommit.setLabel("Continue");
		btnCommit.setFont(Font.getDefault().derive(Font.PLAIN, 20));
		btnCommit.setMargin(5,0,0,56);
    	hfmZone.add(btnCommit);
	}
	
	public void popScreen(){
		UiApplication.getUiApplication().popScreen(this);
		UiApplication.getUiApplication().pushScreen(new SessionScreen());
	}
}
